package net.sxnic.ugr.group.action;

import java.util.Map;

import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.group.Group;
import net.sxnic.ugr.group.GroupManager;
import net.sxnic.ugr.role.Role;
import net.sxnic.ugr.role.util.RoleUtils;

import org.springframework.beans.factory.annotation.Autowired;


@SuppressWarnings("serial")
public class Edit extends UgrActionSupport {

    @Autowired
    private GroupManager groupManager;

    private Group group;


    private Map<String, String> groupsInfo;
    
   
	/**
	 * 用户组所拥有的角色Html checkbox代码
	 */
	private String rolesHtml;
	

	 
	/**
     * @see com.opensymphony.xwork.ActionSupport#execute()
     */
    public String execute() throws Exception {
    	
		try {						
			checkRoles(Role.SYSTEM_ADMIN);
		    this.group = groupManager.get(id);
		    if (group == null) {
		        //addActionError(getText("group.error.notFound"));
		        return INPUT;
		    }
		    
		    rolesHtml = RoleUtils.createCheckboxHtml(group.getRoles(),
					authorizationManager.getRoles(), "role");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
        
       
        return SUCCESS;
    }

   

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public void setGroupManager(GroupManager groupManager) {
        this.groupManager = groupManager;
    }

    public Map<String, String> getGroupsInfo() {
        return groupsInfo;
    }
    
    public String getRolesHtml() {
		return rolesHtml;
	}


	public void setRolesHtml(String rolesHtml) {
		this.rolesHtml = rolesHtml;
	}
	
}
